package uk.ac.shef.ecomm.jdbc.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import uk.ac.shef.ecomm.jdbc.DataAccess;

public  abstract class mysqlDataAccess implements DataAccess
{
	
	// mysql driver class name
	protected String driver = "com.mysql.jdbc.Driver";
	// URL to connect to database
	protected String url = "jdbc:mysql://localhost/rvmsdb";
	//
	protected String USERNAME="root";
	protected String PASSWORD="";
	//
	//TBD: need to check if this should be
	//     moved to indivisual classes
	//     or left as is, accessable by all
	protected Connection connection;
	//
	protected final String UserTBL = "users_tbl";
	protected final String ResearchersTBL = "researchers_tbl";
	protected final String ParticipantsTBL = "participants_tbl";
	protected final String ProjectsTBL = "projects_tbl";
	protected final String PartsInProjTBL = "parts_in_proj_tbl";
	protected final String TimeSlotsTBL = "time_slots_tbl";
	
	/**
	 * Connect to database
	 */
	public void connect() throws Exception
	{
		// load database driver class
		Class.forName(driver);
		//connect to db
		connection = DriverManager.getConnection(url,USERNAME,PASSWORD);
		//setup transaction 
		connection.setAutoCommit(false);
	}
	
	/**
	 * Close connection
	 */
	public abstract void close();
	//public void close()
	//{
	//	try
	//	{
	//		connection.close();
	//	}
	//	catch (SQLException ex)
	//	{
	//		ex.printStackTrace();
	//	}
	//}
}
